<?php


/*
* Copyright (c) 2008-2016 vip.com, All Rights Reserved.
*
* Powered by com.vip.osp.osp-idlc-2.5.11.
*
*/

namespace com\vip\cup\supply\vop\structs\order;

class CupSupplyCreateOrderRequest {
	
	static $_TSPEC;
	public $callScene = null;
	public $openId = null;
	public $orderInfo = null;
	public $orderGoods = null;
	public $orderConsignee = null;
	
	public function __construct($vals=null){
		
		if (!isset(self::$_TSPEC)){
			
			self::$_TSPEC = array(
			100 => array(
			'var' => 'callScene'
			),
			101 => array(
			'var' => 'openId'
			),
			1 => array(
			'var' => 'orderInfo'
			),
			2 => array(
			'var' => 'orderGoods'
			),
			3 => array(
			'var' => 'orderConsignee'
			),
			
			);
			
		}
		
		if (is_array($vals)){
			
			
			if (isset($vals['callScene'])){
				
				$this->callScene = $vals['callScene'];
			}
			
			
			if (isset($vals['openId'])){
				
				$this->openId = $vals['openId'];
			}
			
			
			if (isset($vals['orderInfo'])){
				
				$this->orderInfo = $vals['orderInfo'];
			}
			
			
			if (isset($vals['orderGoods'])){
				
				$this->orderGoods = $vals['orderGoods'];
			}
			
			
			if (isset($vals['orderConsignee'])){
				
				$this->orderConsignee = $vals['orderConsignee'];
			}
			
			
		}
		
	}
	
	
	public function getName(){
		
		return 'CupSupplyCreateOrderRequest';
	}
	
	public function read($input){
		
		$input->readStructBegin();
		while(true){
			
			$schemeField = $input->readFieldBegin();
			if ($schemeField == null) break;
			$needSkip = true;
			
			
			if ("callScene" == $schemeField){
				
				$needSkip = false;
				$input->readI32($this->callScene); 
				
			}
			
			
			
			
			if ("openId" == $schemeField){
				
				$needSkip = false;
				$input->readString($this->openId);
				
			}
			
			
			
			
			if ("orderInfo" == $schemeField){
				
				$needSkip = false;
				
				$this->orderInfo = new \com\vip\cup\supply\vop\structs\order\CupSupplyOrderInfo();
				$this->orderInfo->read($input);
				
			}
			
			
			
			
			if ("orderGoods" == $schemeField){
				
				$needSkip = false;
				
				$this->orderGoods = array();
				$_size0 = 0;
				$input->readListBegin();
				while(true){
					
					try{
						
						$elem0 = null;
						
						$elem0 = new \com\vip\cup\supply\vop\structs\order\CupSupplyOrderGoods();
						$elem0->read($input);
						
						$this->orderGoods[$_size0++] = $elem0;
					}
					catch(\Exception $e){
						
						break;
					}
				}
				
				$input->readListEnd();
				
			}
			
			
			
			
			if ("orderConsignee" == $schemeField){
				
				$needSkip = false;
				
				$this->orderConsignee = new \com\vip\cup\supply\vop\structs\order\CupSupplyOrderConsigneeInfo();
				$this->orderConsignee->read($input);
				
			}
			
			
			
			if($needSkip){
				
				\Osp\Protocol\ProtocolUtil::skip($input);
			}
			
			$input->readFieldEnd();
		}
		
		$input->readStructEnd();
		
		
		
	}
	
	public function write($output){
		
		$xfer = 0;
		$xfer += $output->writeStructBegin();
		
		if($this->callScene !== null) {
			
			$xfer += $output->writeFieldBegin('callScene');
			$xfer += $output->writeI32($this->callScene);
			
			$xfer += $output->writeFieldEnd();
		}
		
		
		if($this->openId !== null) {
			
			$xfer += $output->writeFieldBegin('openId');
			$xfer += $output->writeString($this->openId);
			
			$xfer += $output->writeFieldEnd();
		}
		
		
		$xfer += $output->writeFieldBegin('orderInfo');
		
		if (!is_object($this->orderInfo)) {
			
			throw new \Osp\Exception\OspException('Bad type in structure.', \Osp\Exception\OspException::INVALID_DATA);
		}
		
		$xfer += $this->orderInfo->write($output);
		
		$xfer += $output->writeFieldEnd();
		
		$xfer += $output->writeFieldBegin('orderGoods');
		
		if (!is_array($this->orderGoods)){
			
			throw new \Osp\Exception\OspException('Bad type in structure.', \Osp\Exception\OspException::INVALID_DATA);
		}
		
		$output->writeListBegin();
		foreach ($this->orderGoods as $iter0){
			
			
			if (!is_object($iter0)) {
				
				throw new \Osp\Exception\OspException('Bad type in structure.', \Osp\Exception\OspException::INVALID_DATA);
			}
			
			$xfer += $iter0->write($output);
			
		}
		
		$output->writeListEnd();
		
		$xfer += $output->writeFieldEnd();
		
		$xfer += $output->writeFieldBegin('orderConsignee');
		
		if (!is_object($this->orderConsignee)) {
			
			throw new \Osp\Exception\OspException('Bad type in structure.', \Osp\Exception\OspException::INVALID_DATA);
		}
		
		$xfer += $this->orderConsignee->write($output);
		
		$xfer += $output->writeFieldEnd();
		
		$xfer += $output->writeFieldStop();
		$xfer += $output->writeStructEnd();
		return $xfer;
	}
	
}

?>